/**
 * @author 董一华
 * @since 1.00
 * @version 1.00
 * 
 * TextArea控件
 * 使用说明：
 * jsp中使用范例：最常用模式：<htdz-tag:TextAreaTag name="mymemo" maxlength="30"/>
 * 
 * 参数说明：
 * 1. name为必填项
 * 2. id可以不写，缺省值与name值相同
 * 3. rows可以不写，缺省值为5
 * 4. cols可以不写，缺省值为50
 * 5. maxlength为必填项，允许输入的字数(如：数据表字段长度为varchar2(20),如果此字段允许输入中文，则size必须为10)。
 *  
 * 修订列表： v1.00 2010-01-26 
 * 			修订人：董一华 
 * 			修订内容：初始版本
 * 
 */

package com.zjht.gmcc.bean.tag;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

public class TextAreaTag extends TagSupport {

	private static final long serialVersionUID = -3197207636838457532L;
	private String name;
	private String id;
	private int rows;
	private int cols;
	private int maxlength;

	public TextAreaTag() {
	}

	@SuppressWarnings("static-access")
	public int doStartTag() throws JspException {		
		String name = this.name;
		String id = this.id;
		int rows = this.rows;
		int cols = this.cols;
		int maxlength = this.maxlength;
		
		StringBuilder html = new StringBuilder();

		if (name == null || name.length() == 0) {
			throw new JspException("TextArea控件name参数值不能为空！");
		}
		if (maxlength <= 0)
			throw new JspException("TextArea控件maxlength参数值必须大于0！");

		if (id == null || id.length() == 0)
			id = name;
		if (rows <= 0)
			rows = 5;
		if (cols <= 0)
			cols = 50;
		String fontid = id + "___";

		try {
			html.append("<textarea name=\"");
			html.append(name);
			html.append("\" id=\"");
			html.append(id);
			html.append("\" rows=\"");
			html.append(rows);
			html.append("\" cols=\"");
			html.append(cols);
			html.append("\" onpropertychange=\"checkTextArea(this,'");
			html.append(fontid);
			html.append("',");
			html.append(maxlength);
			html.append(")\" oninput=\"checkTextArea(this,'");
			html.append(fontid);
			html.append("',");
			html.append(maxlength);
			html.append(")\" ></textarea>您还可以输入<font id=\"");
			html.append(fontid);
			html.append("\" color=\"red\">");
			html.append(maxlength);
			html.append("</font>个字 ");
			pageContext.getOut().print(html.toString());
		} catch (Exception e) {
			throw new JspException(e.getMessage());
		}
		html=null;
		return this.SKIP_BODY;
	}

	public void setName(String name) {
		this.name = name;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

	public void setCols(int cols) {
		this.cols = cols;
	}

	public void setMaxlength(int maxlength) {
		this.maxlength = maxlength;
	}
}
